package com.app.backend.config.fastJson;

import com.alibaba.fastjson.serializer.JSONSerializer;
import com.alibaba.fastjson.serializer.ObjectSerializer;
import com.alibaba.fastjson.serializer.SerializeWriter;

import java.io.IOException;
import java.lang.reflect.Type;

/**
 * @program: StringCustomerSerializer
 * @description:
 * @author: Zhun.Xiao
 * @create: 2020-02-26 12:46
 **/
public class StringCustomerSerializer implements ObjectSerializer {

    public static final StringCustomerSerializer instance = new StringCustomerSerializer();

    @Override
    public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features) throws IOException {
        SerializeWriter out = serializer.out;
        String value = object.toString();
        if (value == null || value.length() == 0) {
            out.writeNull();
        } else {
            out.writeString(value.replace("\"", ""));
        }
    }
}